home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EXEC.SWG / 0026_DOS Exec with full memory.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  1KB  |  54 lines

  1. (*
  2. > Can anyone post some code on swapping a TP (7.0) program out of
  3. > memory and executing a batch file (or EXE file; show both if they're
  4. > different please). Thanx.  [I can do it in assembly... :)... but
  5. > Pascal's a different story].
  6.  
  7. With this you must increase the maximum heap with {$M....}. But I found a
  8. very good exec-Routine, which gives all the heap free before executing the
  9. shell:
  10. *)
  11.  
  12. Function DosShell(command:String):Integer;Var
  13.  OldHeapEnd,
  14.  NewHeapEnd: Word;
  15.  Error:Integer;
  16. Begin
  17.  Error:=0;
  18.  If MemAvail<$1000 then Error:=8;
  19.  If Error=0 then Begin
  20.   NewHeapEnd:=Seg(HeapPtr^)-PrefixSeg;
  21.   OldHeapEnd:=Seg(HeapEnd^)-PrefixSeg;
  22.    asm
  23.     mov ah,4Ah
  24.     mov bx,NewHeapEnd
  25.     mov es,PrefixSeg
  26.     Int 21h
  27.     jnc @EXIT
  28.     mov Error,ax
  29.     @EXIT:
  30.    end; {asm}
  31.   If Error=0 then begin
  32.    SwapVectors;
  33.    Exec(GetEnv('COMSPEC'),command);
  34.    SwapVectors;
  35.     asm
  36.      mov ah,4Ah
  37.      mov bx,OldHeapEnd
  38.      mov es,PrefixSeg
  39.      Int 21h
  40.      jnc @EXIT
  41.      mov Error,ax
  42.      @EXIT:
  43.     end; {asm}
  44.   end;   {If}
  45.  end;    {If}
  46.  DosShell:=Error;
  47. end;     {Function}
  48.  
  49. Procedure LittleShellDemo;
  50. Begin
  51.  DosShell('');               { a simple DOS-Shell }
  52.  DosShell('/c TEST.BAT');    { Start the batch-file TEST.BAT }
  53. End;
  54.